package com.project.harmonyledger.common.response;

import lombok.Data;

@Data
public class Result<T> {
  private Integer code;
  private String message;
  private T data;

  public static <T> Result<T> success(T data) {
    Result<T> result = new Result<>();
    result.setCode(ResultCode.SUCCESS.getCode());
    result.setMessage(ResultCode.SUCCESS.getMessage());
    result.setData(data);
    return result;
  }

  public static <T> Result<T> error(ResultCode resultCode) {
    Result<T> result = new Result<>();
    result.setCode(resultCode.getCode());
    result.setMessage(resultCode.getMessage());
    return result;
  }

  public static <T> Result<T> error(ResultCode resultCode, T data) {
    Result<T> result = new Result<>();
    result.setCode(resultCode.getCode());
    result.setMessage(resultCode.getMessage());
    result.setData(data);
    return result;
  }
}